package handler

import (
	"aiRole/internal/dto/request"
	result "aiRole/internal/dto/reslult"
	initSystem "aiRole/pkg/init"
	"github.com/gin-gonic/gin"
	"strconv"
)

func (h RoleHandler) Skill(c *gin.Context) {
	var req request.SkillSaveRequest
	err := c.ShouldBindBodyWithJSON(&req)
	if err != nil {
		initSystem.Logger.Error(err.Error())
		result.Error(c, 500, "参数错误")
		return
	}
	h.Service.SaveSkill(c, req)
}

func (h RoleHandler) SkillList(context *gin.Context) {
	id, err := strconv.ParseInt(context.Param("sessionId"), 10, 64)
	if err != nil {
		result.Error(context, 500, "参数错误")
		return
	}
	h.Service.SkillList(context, id)

}

func (h RoleHandler) List(c *gin.Context) {
	h.Service.RoleList(c)
}

func (h RoleHandler) Search(c *gin.Context) {
	query := c.Query("query")
	h.Service.SearchRole(c, query)
}

func (h RoleHandler) AddRole(c *gin.Context) {
	var req request.RoleRequest
	err := c.ShouldBindBodyWithJSON(&req)
	if err != nil {
		initSystem.Logger.Error(err.Error())
		result.Error(c, 500, "参数错误")
		return
	}
	h.Service.SaveRole(c, req)
}

func (h RoleHandler) DeleteRole(c *gin.Context) {
	id := c.Param("id")
	h.Service.DeleteRole(c, id)
}
func (h RoleHandler) ById(c *gin.Context) {
	id := c.Param("id")
	h.Service.ById(c, id)
}
